package com.cskaoyan.service.wx;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class WxFeedbackServiceImpl implements WxFeedbackService{
    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;
    @Override
    public int submitFeedback(MarketFeedback marketFeedback) {
        //参数校验
        //手机号校验
        String mobile = marketFeedback.getMobile();
        if(mobile.length()!=11){
            return 401;
        }
        Subject subject = SecurityUtils.getSubject();
        if(subject.isAuthenticated()){
            MarketUser user = (MarketUser)subject.getPrincipal();
            marketFeedback.setUserId(user.getId());
            marketFeedback.setUsername(user.getUsername());
            marketFeedback.setAddTime(new Date());
            marketFeedback.setDeleted(false);
            marketFeedback.setStatus(0);
            marketFeedback.setUpdateTime(new Date());
            marketFeedbackMapper.insertSelective(marketFeedback);
        }

        return 0;
    }
}
